﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <link href="~/css/Login.css" rel="stylesheet" />
</head>
<body>
    <div id="login">
        <h1>Login</h1>
        <input id="username" type="text" placeholder="用户名" name="u" />
        <input id="userpassword" type="password" placeholder="密码" name="p" />
        <button id="Login" class="but" type="submit" onclick="submitonclick()">登录</button>
    </div>
</body>
</html>
<script src="~/js/jquery/jquery.js"></script>
<script type="text/javascript">
    function submitonclick()
    {
        if ($('#username').val().trim() == "" || $('#userpassword').val().trim()=="") {
            return alert("账号或密码不能为空");
        }
        //改变登录按钮颜色，文本，禁用点击事件
        //document.getElementById("Login").setAttribute("class", "btnlinethe");
        document.getElementById("Login").innerText = "登陆中...";
        console.log(document.getElementById("Login").innerText);
        document.getElementById("Login").disabled = true;

        $.ajax({
            type: "POST",
            url: "/Login/CheckLogin",
            cache: false,
            async: false,//同步
            data: { "username": $('#username').val().trim(), "userpassword":$('#userpassword').val().trim() },
            success: function (result) {
                console.log(result);
                if (result.code == 0) {
                    setTimeout(function () {
                        console.log("登录成功,跳转到主页面！");
                        window.parent.location = "/Home/Index";
                    }, 1500);
                }
                else {
                    alert(result.msg);
                    document.getElementById("Login").innerText = "登 陆";
                    document.getElementById("Login").disabled = false;
                }
            }
        });
    }
</script>